#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
	float faHeight, moHeight;
	float myHeight;
	char sports;
	char diet;
	char sex;
	scanf("%c %c %c %f %f", &sex, &sports, &diet, &faHeight, &moHeight);
	if (sex == 'M')
	{
		
		if (sports == 'Y' && diet == 'Y')
		{myHeight = (faHeight + moHeight) * 0.54 * 0.02 + (faHeight + moHeight) * 0.54 * 0.015+(faHeight + moHeight) * 0.54;
		printf("%f", myHeight);
		}
		else if (sports == 'N' && diet == 'Y')
		{myHeight = (faHeight + moHeight) * 0.54 * 0.015+ (faHeight + moHeight) * 0.54;
		printf("%f", myHeight);
		}
		else if (sports == 'Y' && diet == 'N')
		{
			myHeight = (faHeight + moHeight) * 0.54 * 0.02+ (faHeight + moHeight) * 0.54;
			printf("%f", myHeight);
		}
		else if (sports == 'N' && diet == 'N')
		{
			myHeight = (faHeight + moHeight) * 0.54;
			printf("%f", myHeight);
		}

	}


	if (sex == 'F');
	{
		
		if (sports == 'Y' && diet == 'Y')

		{
			myHeight = (faHeight + moHeight) / 2+((faHeight + moHeight) / 2) * 0.02 + ((faHeight + moHeight) / 2) * 0.015;
			printf("%f", myHeight);
		}
		else if (sports == 'N' && diet == 'Y')
		{
			myHeight = (faHeight + moHeight) / 2 * 0.015+ (faHeight + moHeight) / 2;
			printf("%f", myHeight);
		}
		else if (sports == 'Y' && diet == 'N')
		{
			myHeight = (faHeight + moHeight) / 2 * 0.02+ (faHeight + moHeight) / 2;
			printf("%f", myHeight);
		}
		else if (sports == 'N' && diet == 'N')
		{
			myHeight = (faHeight + moHeight) / 2;
			printf("%f", myHeight);
		}
	}
	return 0;
}